package ui.panels.primary.players;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JList;

import org.apache.log4j.Logger;

import ui.flowManager.expirimentProperties.ExperimentProperties;
import ui.panels.menus.PlayerPopupMenu;

/**
 * @author vladimir && alon
 *
 */
class MouseJListener extends MouseAdapter{
	private PlayersPanel playersPanel = null;
	private ExperimentProperties props = null;  
	Logger log = Logger.getLogger(this.getClass());
	
	public MouseJListener(PlayersPanel panel, ExperimentProperties props){
	  this.playersPanel = panel;
	  this.props = props;
	}
    

  public void mouseClicked(MouseEvent e){
   if(e.getClickCount() == 2){
	   JList jlist = playersPanel.getList();
	   int index = jlist.locationToIndex(e.getPoint());
	   //case empty place
	   if (index == -1)
	   {
		   return;
	   }
	   
	   log.debug("double click on control player " + index + 1);
	   
	   // call to function that do the rest
	   playersPanel.executeListGame(jlist, index + 1);
     }
   }
  
  
  public void mouseReleased(MouseEvent e)
  {
	  //case right click
	  if (e.getButton() == 3)
	  {
		  JList jlist = playersPanel.getList();
		  int index = jlist.locationToIndex(e.getPoint());
		  jlist.clearSelection();
		  
		  log.debug("right click on control player " + index + 1);
		  jlist.setSelectedIndex(index);
		  PlayerPopupMenu menu = new PlayerPopupMenu(index+1, playersPanel , props);
	      menu.show(e.getComponent(), e.getX(), e.getY());
	  }
  }
}
